package com.itheima.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.itheima.annotation.Log;
import com.itheima.dao.ClazzMapper;
import com.itheima.dto.ClazzAndEmpDTO;
import com.itheima.po.*;
import com.itheima.pojo.Result;
import com.itheima.service.ClazzService;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ClazzServiceImpl implements ClazzService {
    @Resource
    ClazzMapper clazzMapper;

    @Override
    public Result selectClazzPage(SelectClazzParam param) {
        Page<Object> objects = PageHelper.startPage(param.getPage(), param.getPageSize());
        List<ClazzAndEmpDTO> clazzes = clazzMapper.selectClazz(param);
        PageVO<ClazzAndEmpDTO> pageVO =new PageVO<>();
        pageVO.setTotal(objects.getTotal());
        pageVO.setRows(clazzes);
        return Result.success(pageVO);
    }

    @Override
    @Log
    public Result insert(InserClazz clazz) {
        int i = clazzMapper.insert(clazz);
        return Result.success("成功插入"+i+"条数据");
    }

    @Override
    @Log
    public Result deleteById(Integer id) {
        int i = clazzMapper.deleteById(id);
        return Result.success("成功删除"+i+"条数据");
    }

    @Override
    public Result selectById(Integer id) {
        ClazzSelectById clazzSelectById = clazzMapper.selectClazzById(id);
        return Result.success(clazzSelectById);
    }

    @Override
    @Log
    public Result update(UpdateClazz clazz) {
        int update = clazzMapper.update(clazz);
        return Result.success("成功修改"+update+"条数据");
    }

    @Override
    public Result selectAll() {
        List<SelectAllClazz> selectAllClazzes = clazzMapper.selectAll();
        return Result.success(selectAllClazzes);
    }
}
